<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="记录日期" prop="recorddate">
      <el-input v-model="dataForm.recorddate" placeholder="记录日期"></el-input>
    </el-form-item>
    <el-form-item label="登记中心行号" prop="bdcno">
      <el-input v-model="dataForm.bdcno" placeholder="登记中心行号"></el-input>
    </el-form-item>
    <el-form-item label="接收参与者行号" prop="bankno">
      <el-input v-model="dataForm.bankno" placeholder="接收参与者行号"></el-input>
    </el-form-item>
    <el-form-item label="发送时间" prop="sendtime">
      <el-input v-model="dataForm.sendtime" placeholder="发送时间"></el-input>
    </el-form-item>
    <el-form-item label="请求报文" prop="content">
      <el-input v-model="dataForm.content" placeholder="请求报文"></el-input>
    </el-form-item>
    <el-form-item label="剩余次数" prop="timesleft">
      <el-input v-model="dataForm.timesleft" placeholder="剩余次数"></el-input>
    </el-form-item>
    <el-form-item label="状态:0-发送失败;1-发送成功" prop="state">
      <el-input v-model="dataForm.state" placeholder="状态:0-发送失败;1-发送成功"></el-input>
    </el-form-item>
    <el-form-item label="结果码" prop="status">
      <el-input v-model="dataForm.status" placeholder="结果码"></el-input>
    </el-form-item>
    <el-form-item label="结果描述" prop="descinfo">
      <el-input v-model="dataForm.descinfo" placeholder="结果描述"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          seqno: 0,
          recorddate: '',
          bdcno: '',
          bankno: '',
          sendtime: '',
          content: '',
          timesleft: '',
          state: '',
          status: '',
          descinfo: '',
          remark: ''
        },
        dataRule: {
          recorddate: [
            { required: true, message: '记录日期不能为空', trigger: 'blur' }
          ],
          bdcno: [
            { required: true, message: '登记中心行号不能为空', trigger: 'blur' }
          ],
          bankno: [
            { required: true, message: '接收参与者行号不能为空', trigger: 'blur' }
          ],
          sendtime: [
            { required: true, message: '发送时间不能为空', trigger: 'blur' }
          ],
          content: [
            { required: true, message: '请求报文不能为空', trigger: 'blur' }
          ],
          timesleft: [
            { required: true, message: '剩余次数不能为空', trigger: 'blur' }
          ],
          state: [
            { required: true, message: '状态:0-发送失败;1-发送成功不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '结果码不能为空', trigger: 'blur' }
          ],
          descinfo: [
            { required: true, message: '结果描述不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.seqno = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.seqno) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcresend/info/${this.dataForm.seqno}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.recorddate = data.bdcResend.recorddate
                this.dataForm.bdcno = data.bdcResend.bdcno
                this.dataForm.bankno = data.bdcResend.bankno
                this.dataForm.sendtime = data.bdcResend.sendtime
                this.dataForm.content = data.bdcResend.content
                this.dataForm.timesleft = data.bdcResend.timesleft
                this.dataForm.state = data.bdcResend.state
                this.dataForm.status = data.bdcResend.status
                this.dataForm.descinfo = data.bdcResend.descinfo
                this.dataForm.remark = data.bdcResend.remark
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcresend/${!this.dataForm.seqno ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'seqno': this.dataForm.seqno || undefined,
                'recorddate': this.dataForm.recorddate,
                'bdcno': this.dataForm.bdcno,
                'bankno': this.dataForm.bankno,
                'sendtime': this.dataForm.sendtime,
                'content': this.dataForm.content,
                'timesleft': this.dataForm.timesleft,
                'state': this.dataForm.state,
                'status': this.dataForm.status,
                'descinfo': this.dataForm.descinfo,
                'remark': this.dataForm.remark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
